using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Microsoft.Win32;

using DebugCompanion.Properties;

namespace DebugCompanion.Engine
{
	static class EnvironmentUtil
	{
		public static string GetDotNetSdk2Path()
		{
			string res = (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\",
				"sdkInstallRootv2.0", null);
			if (string.IsNullOrEmpty(res))
				throw new Exception(".NET SDK 2 installation path not found");
			return res;
		}

		public static string GetDotNet2Path()
		{
			string res = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory();
			if (string.IsNullOrEmpty(res))
				throw new Exception(".NET Framework 2 installation path not found");
			return res;
		}

		public static string GetCachePath()
		{
			string path = Settings.Default.CachePath;
			if (string.IsNullOrEmpty(path))
			{
				path = Path.GetTempPath() + "\\" + (Guid.NewGuid()).ToString() + "\\";
				Settings.Default.CachePath = path;
				Settings.Default.Save();
			}
			return path;
		}

		public static string GetAsmCachePath(AssemblyInfo asm)
		{
			return GetCachePath() + @"\" + asm.DisplayName + @"\";
		}
	}
}
